package com.jml.jdk8.方法引用;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.junit.Test;

/**
 * @author:jml
 * @date: 2019/12/3 0003 21:58
 * @description：
 */
public class StudentTest003类名and方法 {

    public static void main(String[] args) {
        Student zs = new Student("zs", 10);
        Student ls = new Student("ls", 40);
        Student ww = new Student("ww", 50);
        Student zl = new Student("zl", 90);
        List<Student> students = new ArrayList<>();
        students.add(zs);
        students.add(zl);
        students.add(ls);
        students.add(ww);
        //类名：：实例方法名
        Comparator<Student> compareScore = Student::compareScore;
        students.sort(Student::compareScore);
        //compareScore这个实例方法是sort中lambda表达式的第一个参数调用的
        //除了第一个参数之外，之后的所有参数都做为compareScore方法的参数出入进去
        students.forEach(a-> System.out.println(a.getScore()));

        //类名：：实例方法名
        students.sort(Student::compareName);
        /*Comparator<Student> compareName = Student::compareName;
        compareName.compare(students.get(0),students.get(1));
        students.get(0)去调用compareName方法，students.get(1)作为参数
        */
        students.forEach(a-> System.out.println(a.getName()));

    }

    /**
     * 替代的只是一个函数接口,根据对象的方法的类型得到相应的函数接口的实例
     */
    @Test
    public void 方法引用001(){
        Function<Integer, Integer> function = new Function<Integer, Integer>() {
            @Override
            public Integer apply(Integer integer) {
                return null;
            }
        };
        BiFunction<StudentTest003类名and方法, Integer, Integer> biFunction = StudentTest003类名and方法::tt1;
        Integer apply = biFunction.apply(new StudentTest003类名and方法(),200);
        System.out.println(apply);
    }

    public Integer tt1(Integer integer){
        return integer*3;
    }
}
